﻿#ifndef QGEOTILEDMAPREPLYCUSTOM_H
#define QGEOTILEDMAPREPLYCUSTOM_H

#include <QtNetwork/QNetworkReply>
#include <QtLocation/private/qgeotiledmapreply_p.h>
#include <QTimer>

#include "MapEngineData.h"

class QGeoTiledMapReplyCustom : public QGeoTiledMapReply
{
    Q_OBJECT
public:
    QGeoTiledMapReplyCustom(QNetworkAccessManager*  networkManager, const QNetworkRequest& request,
                            const QGeoTileSpec &spec, QObject *parent = nullptr);
    ~QGeoTiledMapReplyCustom() override;
    void abort() override;

signals:
    void terrainDone            (QByteArray responseBytes, QNetworkReply::NetworkError error);

private slots:
    void _networkReplyFinished   ();
    void _networkReplyError      (QNetworkReply::NetworkError error);
    void _cacheReply             (CacheTile* tile);
    void _cacheError             (MapTask::TaskType type, QString errorString);
    void _timeout                ();  // onTimeout

private:
    void _clearReply();

private:
    QNetworkReply*          _reply;
    QNetworkRequest         _request;
    QNetworkAccessManager*  _networkManager;
    QByteArray              _badMapbox;
    QTimer                  _timer;
    static QByteArray       _bingNoTileImage;
    static int              _requestCount;
};

#endif // QGEOTILEDMAPREPLYCUSTOM_H
